/* Copyright 2010 by Matt Van Der Westhuizen */

package org.chaoticengine.ast.pattern;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Subject from the Subject-Observer design pattern.
 * 
 * @author Matt Van Der Westhuizen <mattpwest@gmail.com>
 */
public class Model {
    protected List<ViewController> observers = new ArrayList<ViewController>();

    /** Notifies all observers that this model has changed. */
    protected void refreshObservers() {
        Iterator<ViewController> it = observers.iterator();
        while (it.hasNext()) {
            it.next().refresh(this);
        }
    }

    public void addObserver(ViewController ob) {
        observers.add(ob);
        ob.refresh(this);
    }

    public void removeObsever(ViewController ob) {
        observers.remove(ob);
    }
}
